package com.ellecity06.common.engine

import android.content.Context
import android.net.Uri
import com.luck.picture.lib.engine.CompressFileEngine
import com.luck.picture.lib.interfaces.OnKeyValueResultCallbackListener
import top.zibin.luban.Luban
import top.zibin.luban.OnNewCompressListener
import java.io.File
import java.util.ArrayList

/**
 * @author ellecity06
 * @time 2024/12/4 10:58
 * @des
 */
class CustomCompressEngine : CompressFileEngine {
    override fun onStartCompress(context: Context?, source: ArrayList<Uri>?, call: OnKeyValueResultCallbackListener?) {
        Luban.with(context).load(source).ignoreBy(100)
            .setCompressListener(object : OnNewCompressListener {
                override fun onStart() {
                }

                override fun onSuccess(source: String?, compressFile: File?) {
                    call?.onCallback(source, compressFile?.absolutePath)
                }

                override fun onError(source: String?, p1: Throwable?) {
                    call?.onCallback(source, null)
                }

            }).launch()
    }
}